//
//  PrivacySetViewController.m
//  carcareIOS
//
//  Created by 王然 on 16/6/28.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "PrivacySetViewController.h"

#import "TraProtectViewController.h"
#import "GesturePWSetViewController.h"

#define SECTION_HEIGHT (11)
#define CELLHEIGHT 45

@interface PrivacySetViewController ()

@property (nonatomic , readonly) NSArray * titleArray;

@end

@implementation PrivacySetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"隐私设置";
    
    self.tableView.frame = CGRectMake(0, 0, __MAIN_WIDTH, __MAIN_HEIGHT_64);
    self.tableView.backgroundColor = [Theme backGroundColor];
    self.tableView.scrollEnabled = YES;
    self.tableView.separatorColor = [Theme lineColor];
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
}
-(NSArray *)titleArray
{
    return @[@[@"空白"],@[@"行驶轨迹",@"手势"],@[@"＊隐私设置仅针对行程"]];
}
#pragma mark - tableView delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.titleArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.titleArray[section] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return (indexPath.section == 1 ? CELLHEIGHT : (indexPath.section == 2 ? SECTION_HEIGHT * 3 : SECTION_HEIGHT)) ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell;
    switch (indexPath.section) {
        case 1:
        {
            NSString *identifier = @"SettingsCell";
            cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
                                              reuseIdentifier:identifier];
                [[[UIView viewWithFrame:CGRectMake(0, 0, __MAIN_WIDTH, 0.5)] resetBackgroundColor:[Theme lineColor]] setupOnView:cell.contentView];
                [[[UIView viewWithFrame:CGRectMake(0, CELLHEIGHT, __MAIN_WIDTH, 0.5)] resetBackgroundColor:[Theme lineColor]] setupOnView:cell.contentView];
                
                [Factory imageViewWithCenter:CGPointMake(__MAIN_WIDTH - 25, CELLHEIGHT/2) image:ImageNamed(@"cell_right") onView:cell.contentView];
                
            }
            
            cell.textLabel.text = self.titleArray[indexPath.section][indexPath.row];
            cell.textLabel.font = FONT_TABLE_TITLE;
            cell.textLabel.textColor = [Theme wordColor];
            
        }
            break;
            //空白cell
        case 0:
        case 2:
        {
            NSString * cellID = (indexPath.section == 2 ? @"noChoiceCellID" : @"noCellID");
            cell = [tableView dequeueReusableCellWithIdentifier:cellID];
            if (!cell) {
                cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
                
                if(indexPath.section == 0)
                {
                    UIView * backView = [[[UIView viewWithFrame:CGRectMake(0, 0, __MAIN_WIDTH, (indexPath.section == 0 ? SECTION_HEIGHT : SECTION_HEIGHT * 2))] resetBackgroundColor:[Theme backGroundColor]] setupOnView:cell];
                    backView.layer.borderColor = (indexPath.section == 2 ? [UIColor clearColor] : [Theme lineColor]).CGColor;
                    backView.layer.borderWidth = 0.5;

                }
            }
            cell.backgroundColor = [Theme backGroundColor];
            if(indexPath.section == 2)
            {
                cell.textLabel.text = self.titleArray[indexPath.section][indexPath.row];
                cell.textLabel.font = FONT_DEFAULT_Light(12);
                cell.textLabel.textColor = [Theme wordGrayColor];
            }
        }
            break;
        default:
            break;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([Check isVisiter])
    {
        return;
    }
    if (indexPath.section == 1) {
        switch (indexPath.row) {
            case 0://行驶轨迹
                [self.navigationController pushViewController:[[[TraProtectViewController alloc] initWithTableRefreshType:TYPE_TABLE_REFRESH_NONE] navSetupBackItemWithIdentification:BACK_ICON_TITLE] animated:YES];
                break;
            case 1://手势
                [self.navigationController pushViewController:[[[GesturePWSetViewController alloc] initWithTableRefreshType:TYPE_TABLE_REFRESH_NONE] navSetupBackItemWithIdentification:BACK_ICON_TITLE] animated:YES];
                break;
            default:
                break;
        }
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
